package com.psp.bu.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.bu.model.ProductBean;
import com.psp.bu.model.UserProductRelationBean;
import com.psp.bu.persist.dao.BusinessDao;

@Repository
public class BusinessImpl extends BaseImpl implements BusinessDao {

	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".BusinessMapper";

	@Override
	public ProductBean selectById(String pid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectById", pid);
	}

	@Override
	public int insert(ProductBean product) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", product);
	}

	@Override
	public int insertUserProduct(UserProductRelationBean userproduct) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insertUserProduct", userproduct);
	}

	@Override
	public int selectProductCount(String bid, int shelfState) {
		Map<String, Object> where = new HashMap<>();
		where.put("buid", bid);
		where.put("state", shelfState);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectProductCount", where);
	}

	@Override
	public List<ProductBean> selectProductList(int page, int pageSize, String bid, int shelfState) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		where.put("buid", bid);
		where.put("state", shelfState);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectProductList", where);
	}

}
